import 'dart:math';
import 'dart:typed_data';

import 'package:flutter/material.dart' hide Image;
import 'package:flutter/services.dart';
import 'package:image/image.dart';

class Utils {
  // 拼接图片
  static mergeImage(Uint8List image, BuildContext context) async {
    ByteData imageData = await rootBundle.load('lib/asserts/red.png');
    List<int> bytes = Uint8List.view(imageData.buffer);
    Image bottomImage = decodePng(bytes) as Image;

    var image2 = decodeImage(image) as Image;
    // 拉伸底部二维码适应截图
    bottomImage = copyResize(bottomImage,
        width: image2.width, height: bottomImage.height);

    final mergedImage = Image(max(bottomImage.width, image2.width),
        bottomImage.height + image2.height);
    copyInto(mergedImage, image2, blend: false);
    copyInto(mergedImage, bottomImage, dstY: image2.height, blend: true);
    List<int> newJpeg = encodePng(mergedImage);
    return newJpeg;
  }
}
